<%--
  Created by IntelliJ IDEA.
  User: hongfive
  Date: 2019/1/9
  Time: 21:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basepath = request.getScheme()
            + "://" + request.getServerName()
            + ":" + request.getServerPort() + "/" + path;
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>详情</title>
    <link rel="stylesheet" href="<%=basepath%>/statics/style/css/detail.css">
    <link rel="stylesheet" href="<%=basepath%>/statics/style/css/common.css">
    <link rel="stylesheet" href="<%=basepath%>/statics/style/css/message.css">
    <script src="<%=basepath%>/statics/style/js/jquery.min.js"></script>

    <script>
        function formatDate(now) {
            var now = new Date(now);
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            return year + "年" + fixZero(month, 2) + "月" + fixZero(date, 2)
                + "日" + fixZero(hour, 2) + ":" + fixZero(minute, 2) + ":"
                + fixZero(second, 2);
        }
        //时间如果为单位数补0
        function fixZero(num, length) {
            var str = "" + num;
            var len = str.length;
            var s = "";
            for (var i = length; i-->len;) {
                s += "0";
            }
            return s + str;
        }
        //获取地址栏中的键值对
        function getUrlPara(paraName){
            var sUrl = location.href;
            var sReg = "(?:\\?|&){1}"+paraName+"=([^&]*)"
            var re=new RegExp(sReg,"gi");
            re.exec(sUrl);
            return RegExp.$1;
        }
        /*//图片的字符串拼接
        function setimgformat(str){
            var temp=str.split("\\\\");
            console.log(temp);
            var path="../statics/image/"
            var realpath=path+temp[2];
            return realpath;
        }*/
        $(function () {
            $("#addmsg").attr("href","../message/insert?cid="+getUrlPara("cid")+"");
            var c_data=new Object();
            var cid=getUrlPara("cid");
            $.ajax({
                url:'../canvas/Cone',
                dataType: 'json',
                data:{
                    cid:cid
                },
                async:false,
                type:"POST",
                success: function (data) {
                    var json=data;
                    if (json.code==1){
                        c_data=json.data;
                        console.log(json.data);
                        //展示内容
                        var dom="<div class=\"section\" style=\"margin-top:20px;\">\n" +
                            "        <div class=\"width1200\">\n" +
                            "            <div class=\"fl\"><img width=\"720px\" height=\"432\" src=\"../statics/image/"+c_data.img+"\"/></div>\n" +
                            "            <div class=\"fl sec_intru_bg\">\n" +
                            "                <dl>\n" +
                            "                    <dt>"+c_data.name+"</dt>\n" +
                            "                    <dd>\n" +
                            "                        <p>发布人：<span>"+c_data.creator+"</span></p>\n" +
                            "                        <p>发布时间：<span>"+formatDate(c_data.createTime)+"</span></p>\n" +
                            "                        <p>修改时间：<span>"+formatDate(c_data.updateTime)+"</span></p>\n" +
                            "                    </dd>\n" +
                            "                </dl>\n" +
                            "                <ul>\n" +
                            "                    <li>售价：<br/><span class=\"price\">"+c_data.price+"</span>元</li>\n" +
                            "                </ul>\n" +
                            "            </div>\n" +
                            "        </div>\n" +
                            "    </div>\n" +
                            "    <div class=\"secion_words\">\n" +
                            "        <div class=\"width1200\">\n" +
                            "            <div class=\"secion_wordsCon\">\n" +
                            "                <p>"+c_data.description+"</p>\n" +
                            "            </div>\n" +
                            "        </div>\n" +
                            "    </div>";
                        $("#content").append(dom);
                    }
                    else {
                        //弹出的提示消息
                    }
                }
            })
            var m_data=new Object();
            $.ajax({
                url:'../message/msg',
                dataType: 'json',
                data:{
                    cid:cid
                },
                async:false,
                type:"POST",
                success: function(data){
                    var json = data;
                    console.log(json);
                    if (json.code == 1){
                        console.log(json.data);
                        m_data = json.data;
                        //展示油画
                        for (var i=0;i<m_data.length;i++){
                           var dom=" <div class=\"alt-head\">\n" +
                               "                    <div class=\"alt-info\">\n" +
                               "                        <span>发布人:"+m_data[i].username+"</span>\n" +
                               "                        <span>发布时间:"+formatDate(m_data[i].createTime)+"</span>\n" +
                               "                    </div>\n" +
                               "                </div>\n" +
                               "                <div class=\"alt-content\">\n" +
                               "                    <p>"+m_data[i].msgcontent+"</p>\n" +
                               "                </div>";
                            $("#Msg").append(dom);
                        }
                    }
                    else {
                        alert("获取留言信息失败！");
                    }
                }
            })

        })


    </script>
</head>
<body class="bgf8">
<div class="header">
    <div class="logo f1">
        <img src="<%=basepath%>/statics/image/logo.png">
    </div>
    <div class="auth fr">
            <% if (null == request.getSession().getAttribute("user")) {%>
            <ul >
                <li><a href="../user/login">登录</a></li>
                <li><a href="">注册</a></li>
            </ul>
            <%} else { %>
            <ul>
                <li>欢迎来到师易文艺态</li>
            </ul>
            <% } %>
    </div>
</div>
<div class="content" id="content">

</div>
<!--留言板-->
<section class="main">
    <div class="container">

    <div class="alt-item" id="Msg">
        <%--<div class="alt-head">
            <div class="alt-info">
                <span>作者</span>
                <span>时间</span>
            </div>
        </div>
        <div class="alt-content">
            <p>我的留言内容</p>
        </div>--%>
    </div>
    </div>

</section>
<section class="page">
    <div class="container">
        <% if (null != request.getSession().getAttribute("user")) {%>
        <div id="fatie">
            <a id="addmsg" href=""><button>点我留言</button></a>
        </div>
        <%} else { %>
        <div id="fatie">
            请<a href="../user/login"><button>登录</button></a>后留言
        </div>
        <% } %>


       <%-- <div id="pagefy">
            <ul>
                <form id="messageForm" action="/message/list.do" method="post">
                    <input type="hidden" id="page" name="page" value="${page}">
                    <input type="hidden" id="last" name="last" value="${last}">
                    <li><a href="javascript:void(0)" onclick="submitMessageForm('first')">首页</a></li>
                    <li><a href="javascript:void(0)" onclick="submitMessageForm('pre')">上一页</a></li>
                    <li><a href="javascript:void(0)">当前第${page}页</a></li>
                    <li><a href="javascript:void(0)" onclick="submitMessageForm('next')">下一页</a></li>
                    <li><a href="javascript:void(0)" onclick="submitMessageForm('last')">尾页</a></li>
                </form>
            </ul>
        </div>--%>
    </div>
</section>
<div class="footer">
    <p><span>M-GALLARY</span>©2017 POWERED BY IMOOC.INC</p>
</div>
</div>
</body>
</html>

